﻿@{
    ViewBag.Title = "ItemIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var type = request('type');
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 52);
            }, 200);
            e.stopPropagation();
        });
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/SecurityPatrol/GetItemList",
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "SPIId", index: "SPIId", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 150, align: "left" },
                { label: "名称", name: "Name", index: "Name", width: 150, align: "left" },
                { label: "单位数量", name: "UnitNum", index: "UnitNum", hidden: true },
                {
                    label: "单位", name: "Unit", index: "Unit", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "天";
                            case 1: return "周";
                            case 2: return "月";
                            case 3: return "季";
                            case 4: return "年";
                        }
                    }
                },
                {
                    label: "频次", name: "Frequency", index: "Frequency", width: 300, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (rowObject.Unit) {
                            case 0: return rowObject.UnitNum + "天" + cellvalue + "次";
                            case 1: return rowObject.UnitNum + "周" + cellvalue + "次";
                            case 2: return rowObject.UnitNum + "月" + cellvalue + "次";
                            case 3: return rowObject.UnitNum + "季" + cellvalue + "次";
                            case 4: return rowObject.UnitNum + "年" + cellvalue + "次";
                        }
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 150, align: "left" }
            ],
            pager: false,
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/SecurityPatrol/GetItemList",
                postData: {
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val()
                }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form1",
            title: '添加巡更项目',
            url: '/PropertyManage/SecurityPatrol/ItemForm',
            width: "700px",
            height: "430px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("SPIId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form1",
                title: '编辑巡更项目',
                url: '/PropertyManage/SecurityPatrol/ItemForm?keyValue=' + keyValue,
                width: "700px",
                height: "430px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("SPIId");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/SecurityPatrol/RemoveItemForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的项目！', 0);
        }
    }

    //保存表单
    function AcceptClick() {
        dialogClose();
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">巡更项目信息</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-addItem" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-editItem" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        @*<a id="lr-detail" class="btn btn-default" onclick="btn_detail()"><i class="fa fa-list-alt"></i>&nbsp;详细</a>*@
                        <a id="lr-deleteItem" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
            </div>
        </div>
    </div>
</div>
